package severlet;

import bean.Fee;
import dao.FeeDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminFeeButtonServlet", value = "/AdminFeeButtonServlet")
public class AdminFeeButtonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        //获取前端数据
        String months = request.getParameter("months");
        String dormitoryid = request.getParameter("dormitoryid");
        String electricfee = request.getParameter("electricfee");
        String electricnum = request.getParameter("electricnum");
        String waterfee = request.getParameter("waterfee");
        String waternum = request.getParameter("waternum");
        if (months=="" || dormitoryid=="" || electricfee=="" || electricnum=="" || waterfee=="" || waternum==""){
            request.getRequestDispatcher("FanHui.jsp").forward(request,response);
        }
        //获取提交按钮
        String botton = request.getParameter("submit");
        //封装
        Fee fee=new Fee();
        fee.setMonths(months);
        fee.setElectricfee(electricfee);
        fee.setDormitoryid(dormitoryid);
        fee.setElectricnum(electricnum);
        fee.setWaterfee(waterfee);
        fee.setWaternum(waternum);

//        调用dao层  根据按钮判断不同的结果
        FeeDao feeDao=new FeeDao();
        if (botton.equals("submit")){
            feeDao.submit(fee);
        }else if (botton.equals("modify")){
            feeDao.changeFeeByDormid(fee);
        }
        //请求转发  修改过号查询
        request.getRequestDispatcher("/AdminFeeServlet").forward(request,response);
    }
}
